package net.oschina.dachuan.kryoserializers;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.EnumMap;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.pool.KryoPool;

/**
 * 
 * @author 张大川
 *
 */
public class PoolTest {
	/**
	 * 
	 * 
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException {

		KryoUitl factory = new KryoUitl();
		KryoPool pool = new KryoPool.Builder(factory).softReferences().build();
		Kryo kryo = pool.borrow();// 对象借出
		EnumMap<Month, String> map = new EnumMap<Month, String>(Month.class);
		// put方法
		FileOutputStream fileOutputStream1 = new FileOutputStream("xxx2");
		map.put(Month.January, "1");
		map.put(Month.February, "2");
		map.put(Month.March, "3");
		Output output1 = new Output(fileOutputStream1);
		//kryo.register(EnumMap.class, new EnumMapSerializer());// 4.0 不支持 enummap
		kryo.writeObject(output1, map);
		output1.close();
		
		Input input1 = new Input(new FileInputStream("xxx2"));
		EnumMap<Month, String> obMap = kryo.readObject(input1, EnumMap.class);
		System.out.println(obMap.toString());
		input1.close();
		
		pool.release(kryo);// 对象归还

	}

}
